'use strict';

angular.module('myApp.account', [])

.controller('accountCtrl',  ['$scope','$http', 
	function($scope,$http) {
        $http.get('v1/account').success(function(data){
            $scope.accounts = data.result['data'];
              console.log(data.result['data']);
        });

	//搜索
	$("#search_send_button").on('click',function(){
		var search_arr = {
			'column' : $("#search_select").val(),
			'content' : $("#search_input").val()
 		}; 
 		console.log(search_arr);
 		$http.post('v1/account/search', search_arr).success(function(data){
            if(!data.error ){
  			console.log(data);
 			$scope.accounts = data.result['data'];           	
            }else{
                alert(data.message);
            }
 		});
	});
      
	//显示全部
	$scope.reload = function(){
        $http.get('v1/account').success(function(data){
            $scope.accounts = data.result['data'];
              console.log(data.result['data']);
        });
	};

	//删除记录
	$scope.delete = function(account){
		$http.delete('v1/account/'+ account.id).success(function(data){
			if( !data.error ){
				$scope.accounts.splice($scope.accounts.indexOf(account),1);
				alert("删除成功");
			}else{
				alert(data.message);
			}
		});
	};
}]);
